package operation;

import book.Book;
import book.BookList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a1227
 * Date: 2022-10-04
 * Time: 12:00
 */
public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除书籍！");
        System.out.println("请输入所要删除的书名:>");
        String name = scanner.nextLine();
        int index = 0;
        int i = 0;
        for(; i < bookList.getSize(); i++){
            if(name.equals(bookList.getBook(i).getName())){
                index = i;
                break;
            }
        }
        if(i == bookList.getSize()){
            System.out.println("所要删除的书不存在！");
            return ;
        }
        for(i = index; i < bookList.getSize() - 1; i++){
            Book book = bookList.getBook(i + 1);
            bookList.setBook(i,book);
        }
        bookList.setSize(bookList.getSize() - 1);
        System.out.println("删除成功！");
    }
}
